package com.lightjet.macross.base.awf.controller;

import com.lightjet.macross.base.awf.service.ProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.java.Log;
import org.springframework.context.annotation.Scope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;

@RestController
@RequestMapping("/pub/api")
@Scope("request")
@Log
@Api(tags="AWF业务流程服务-公开接口集")
public class PublicController {

    @Resource
    private ProcessService processService;

    @GetMapping(value = "/processmap",produces = MediaType.IMAGE_JPEG_VALUE)
    @ResponseBody
    @ApiOperation(value = "流程图查看接口", notes = "根据流程实例ID获取流程图")
    public byte[] View(String piid) throws IOException {
        InputStream imageStream = processService.GetProcessView(piid);
        byte[] bytes = new byte[imageStream.available()];
        imageStream.read(bytes, 0, imageStream.available());
        return bytes;
    }
}
